/* Copyright (c) 2017, NVIDIA CORPORATION.  All rights reserved.
*
* NVIDIA CORPORATION and its licensors retain all intellectual property
* and proprietary rights in and to this software, related documentation
* and any modifications thereto.  Any use, reproduction, disclosure or
* distribution of this software and related documentation without an express
* license agreement from NVIDIA CORPORATION is strictly prohibited.
*/
#include "NVIDIAGfeSDKPrivatePCH.h"
#include "GfeSDKCore.h"


#define VALIDATE_MODULE_CORE()                                           \
    if (!GFEHandle && Callback)                                          \
    {                                                               \
        Callback(GfeSDK::NVGSDK_ERR_MODULE_NOT_LOADED, Context);    \
        return;                                                     \
    }

#define VALIDATE_MODULE_CORE_SPECIALIZED()                                       \
    if (!GFEHandle && Callback)                                                  \
    {                                                                       \
        Callback(GfeSDK::NVGSDK_ERR_MODULE_NOT_LOADED, nullptr, Context);   \
        return;                                                             \
    }

FGfeSDKCore::FGfeSDKCore(GfeSDK::NVGSDK_HANDLE* GFEHandle_)
    : GFEHandle(GFEHandle_)
{
}

FGfeSDKCore::~FGfeSDKCore()
{
}

void FGfeSDKCore::Poll()
{
	if (GFEHandle)
		GfeSDK::NVGSDK_Poll(GFEHandle);
}

void FGfeSDKCore::RequestPermissionsAsync(FGfeSDKRequestPermissionsParams const& Params, GfeSDK::NVGSDK_EmptyCallback Callback, void* Context)
{
    VALIDATE_MODULE_CORE();

	std::vector<GfeSDK::NVGSDK_Scope> Scopes(Params.Scopes.Num());
    
	for (int32 i = 0; i < Params.Scopes.Num(); i++)
	{
		Scopes[i] = TranslateEnum(kScopeUnrealToSdk, Params.Scopes[i], GfeSDK::NVGSDK_SCOPE_MAX);
	}

	GfeSDK::NVGSDK_RequestPermissionsParams cParams;
	cParams.scopeTable = const_cast<GfeSDK::NVGSDK_Scope*>(Scopes.data());
	cParams.scopeTableSize = Scopes.size();
	
	GfeSDK::NVGSDK_RequestPermissionsAsync(GFEHandle, &cParams, Callback, Context);
}

void FGfeSDKCore::GetUILanguageAsync(GfeSDK::NVGSDK_GetUILanguageCallback Callback, void* Context)
{
    VALIDATE_MODULE_CORE_SPECIALIZED();

	GfeSDK::NVGSDK_GetUILanguageAsync(GFEHandle, Callback, Context);
}
